<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/bootstrap/dist/css/bootstrap.css">
    <script src="/socket.io/socket.io.js"></script>
    <script src="/jquery/dist/jquery.js"></script>
    <style>
        *{
            padding: 0;
            margin: 0;
            list-style: none;
        }
        body{
            background-image: url("/images/曹琴默.webp");
            background-size: 1920px;
        }
        .box{
            opacity: 0.7;
            width: 1000px;
            height: 600px;
            margin: 100px auto;
            border: 2px solid #ccc;
        }
        .box1{
            width: 100px;
            height: 100%;
            background-color: #333;
            float: left;
        }

        .box1 img{
            margin-top: 20px;
            margin-left: 20px;
        }

        /* 按钮 */
        .box1 button {
            margin-left: 20px;
            margin-top: 10px;
            background-color: pink;
        }
        .box1 a{
            margin-left: 20px;
            margin-top: 10px;
            background-color: pink;
        }
        
        /* 中间部分大盒子 */
        .box2{
            width: 296px;
            height: 100%;
            background-color: #EAE8E7;
            float: left;
        }
        /* 中间顶部搜索栏 */
        .box2 .search{
            width: 100%;
            height: 80px;
            background-color: #F5F5F5;
        }

        .box .inp{
            width: 80%;
            height: 30px;
            border-radius: 5px;
            margin-top: 25px;
            margin-left: 20px;
            text-align: center;
        }

        /* 中间部分联系人 */
        .box2 .person{
            width: 100%;
            height: 70px;
            border-bottom: 1px solid #ccc;
        }
        .box2 .person img{
            margin-top: 10px;
            margin-left: 10px;
            vertical-align: center;
        }
        .box2 .person span{
            font-size: 16px;
            font-weight: 400;
            
        }

        /* 右侧聊天室 */
        .box3{
            width: 600px;
            height: 100%;
            background-color: #F5F5F5;
            float: left;
            
        }
        /* 右侧顶部 */
        .box3-top{
            width: 100%;
            height: 80px;
            border-left: 1px solid #ccc;
        }

        .box3-top span{
            line-height: 80px;
            margin-left: 20px;
            font-size: 20px;
        }
        /* 右侧中间 */
        .box3-middle{
            width: 100%;
            height: 400px;
            border-top: 1px solid #ccc;
            overflow: auto;
        }

        #kuang{
            display: none;
        }

        /* 对话 */

        .right{
            width: 100%;
            height: 50px;
        }
        .right-user-speak{
            height: 50px;
            padding: 6px 8px ;
            background-color: pink;
            border-radius: 5px;
        }
        .left{
            width: 100%;
            height: 50px;
        }

        .left-user{
            float: right;
        }

        .left-user-speak{
            /* height: 50px; */
            padding: 6px 8px ;
            background-color: #9EEA6A;
            border-radius: 5px;
            float: right;
        }


        /* 右侧底部 */
        
        .box3-bottom{
            width: 100%;
            height: 120px;
            background-color: #FFFFFF;
            border: 1px solid #ccc;
            position: relative;
        }

        textarea{
            width: 100%;
            height: 70px;
            border: 1px solid #e1e1e1;
        }
        /* 发送按钮 */
        .box3-bottom button{
            background-color: pink;
        }

    </style>
</head>
<body>
    <div class="box">
        <img src="" alt="">

        <!-- 左侧登录人员 -->
        <div class="box1">
            <h1><img src="/images/1.jpg" alt="" width="60px"></h1>

            <!-- <a class="btn btn-danger" href="/login">登录</a><br> -->
            <a href="/out" class="btn btn-info out">退出</a>
        <!-- 左侧登陆人员结束 -->
        </div>


        <!-- 中间在线人员 -->
        <div class="box2">
            <!-- 中间搜索栏 -->
            <div class="search">
                <input class="inp" type="text" placeholder="搜索">
            </div>
            <div class="person">
                <img src="/images/2.webp" alt="" width="50px">
                <span>小丽子</span>
            </div>

            <div class="person">
                <img src="/images/2.webp" alt="" width="50px">
                <span>小丽子</span>
            </div>

            <div class="person">
                <img src="/images/2.webp" alt="" width="50px">
                <span>小丽子</span>
            </div>
        <!-- 中间在线人员结束 -->
        </div>


        <!-- 右侧聊天窗口 -->
        <div class="box3">
            <!-- 顶部 名字+设置窗口 -->
            <div class="box3-top">
                <span>雷神的马大锤</span>
            </div>

            <div class="box3-middle">


            </div>

            <div id="kuang">
                
                    <div class="left">
                        <span class="left-user"><b></b>:</span>
                        <span class="left-user-speak">周末给你做油焖大虾~</span>
                    </div>
                

                <div class="right">
                    <span class="right-user"><b>小马</b>:</span>
                    <span class="right-user-speak">再加一碗臭粉！！</span>
                </div>

                <div class="up"><b>小丽</b>上线啦~</div>
                <div class="outt"><b>小丽</b>离线了</div>
            </div>

            <div class="box3-bottom">
                <textarea id="text" name="text" style="resize:none"></textarea>
                <button class="btn btn-info send">发送</button>
                <button id="history" class="btn btn-info">历史</button>
            </div>
        <!-- 右侧聊天窗口结束 -->
        </div>
    <!-- 总盒子结束 -->
    </div>
<script>
      let socket = io.connect("/");
    //   let name = prompt("请输入你的名字");
   
      $('.send').click(function(){
        alert("请先登录")
        location.href = "/login"
      })

      //点击回车发送信息
      $(window).keydown(e=>{
        if(e.keyCode == 13){
          //让前边的元素执行一次参数中的事件
          $('.send').trigger('click');
          return false;
        }
      })
      // 接收服务端广播出来的信息
      socket.on("msx020703",res=>{
        //克隆right 节点
        let o = $('#kuang .right').clone();
        o.find('.right-user-speak').html(res.msg);
        o.find('.right-user b').html(res.name);
        $('.box3-middle').append(o);
        console.log(res);
      })

        
        // 进入聊天室
        socket.emit('up', { name: '游客' })
        socket.on('up', res => {
            let up = $('#kuang .up').clone();
            up.html(res.name+"上线了");
            $('.box3-middle').append(up);
        })

        // 退出聊天室
        $('.out').on('click', function () {
            socket.emit('outt', { name: '游客' })
        })
        socket.on('outt', res => {
            let out = $('#kuang .outt').clone();
            out.html(res.name+"下线了");
            $('.box3-middle').append(out);
        })
</script>
</body>
</html>